home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2001 December / pcwk12201b.iso / Wersje pelne i specjalne / Winamp 2.77 i 3.0beta / wasabi-sdk_beta1.exe / studio / common / virtualwnd.cpp < prev    next >
C/C++ Source or Header  |  2001-10-08  |  13KB  |  498 lines

  1. /*
  2.  
  3.   Nullsoft WASABI Source File License
  4.  
  5.   Copyright 1999-2001 Nullsoft, Inc.
  6.  
  7.     This software is provided 'as-is', without any express or implied
  8.     warranty.  In no event will the authors be held liable for any damages
  9.     arising from the use of this software.
  10.  
  11.     Permission is granted to anyone to use this software for any purpose,
  12.     including commercial applications, and to alter it and redistribute it
  13.     freely, subject to the following restrictions:
  14.  
  15.     1. The origin of this software must not be misrepresented; you must not
  16.        claim that you wrote the original software. If you use this software
  17.        in a product, an acknowledgment in the product documentation would be
  18.        appreciated but is not required.
  19.     2. Altered source versions must be plainly marked as such, and must not be
  20.        misrepresented as being the original software.
  21.     3. This notice may not be removed or altered from any source distribution.
  22.  
  23.  
  24.   Brennan Underwood
  25.   brennan@nullsoft.com
  26.  
  27. */
  28.  
  29. #include "virtualwnd.h"
  30. #include "region.h"
  31. #include "../studio/api.h"
  32. #include "../common/usermsg.h"
  33.  
  34. VirtualWnd::VirtualWnd() {
  35.     virtualX = virtualY = virtualH = virtualW = 0;
  36.     inited = 0;
  37.     visible = 0;
  38.   bypassvirtual = 0;
  39. }
  40.  
  41. VirtualWnd::~VirtualWnd() {
  42.   if (!bypassvirtual) {
  43.     if (getParent())
  44.       getParent()->removeVirtualChild(this);
  45.   }
  46. }
  47.  
  48. int VirtualWnd::init(RootWnd *parWnd, int nochild) {
  49.   if (!bypassvirtual) 
  50.     setParent(parWnd);
  51.   return(VIRTUALWND_PARENT::init(parWnd,nochild));
  52. }
  53.  
  54. int VirtualWnd::init(HINSTANCE hInstance, HWND parent, int nochild) {
  55.   if (!bypassvirtual) {
  56.     ASSERTPR(getParent()!=NULL, "Virtual window created without specifying BaseWnd parent");
  57.     getParent()->addVirtualChild(this);
  58.     if (getStartHidden())
  59.       visible = 0;
  60.     else
  61.       visible = 1;
  62.     inited = 1;
  63.       onInit();
  64.       return 1;
  65.   } else
  66.     return VIRTUALWND_PARENT::init(hInstance, parent, nochild);
  67. }
  68.  
  69. HWND VirtualWnd::gethWnd() {
  70. //    ASSERTPR(getParent() != NULL, "Virtual window used as base parent !");
  71.   if (!bypassvirtual) {
  72.       if(!getParent()) return NULL;
  73.       return(getParent()->gethWnd());
  74.   } else
  75.    return VIRTUALWND_PARENT::gethWnd();
  76. }
  77.  
  78. HINSTANCE VirtualWnd::gethInstance() {
  79.   if (!bypassvirtual) {
  80.     if(!getParent()) return NULL;
  81.     return HINSTANCEfromHWND(getParent()->gethWnd());
  82.   } else
  83.    return VIRTUALWND_PARENT::gethInstance();
  84. }
  85.  
  86. int VirtualWnd::setTimer(int id, int ms) {
  87.   if (!bypassvirtual) {
  88.     ASSERT(getRootParent() != NULL);
  89.     return(getRootParent()->setVirtualChildTimer(this, id, ms));
  90.   } else
  91.    return VIRTUALWND_PARENT::setTimer(id, ms);
  92. }
  93.  
  94. int VirtualWnd::killTimer(int id) {
  95.   if (!bypassvirtual) {
  96.     ASSERT(getRootParent() != NULL);
  97.       return(getRootParent()->killVirtualChildTimer(this, id));
  98.   } else
  99.    return VIRTUALWND_PARENT::killTimer(id);
  100. }
  101.  
  102. void VirtualWnd::resize(RECT *r) {
  103.   if (!bypassvirtual) {
  104.     resize(r->left, r->top, r->right-r->left, r->bottom-r->top);
  105.   } else
  106.    VIRTUALWND_PARENT::resize(r);
  107. }
  108.  
  109. void VirtualWnd::resize(int x, int y, int w, int h) {
  110.   if (!bypassvirtual) {
  111.     if (isVisible()) {
  112.       RECT r;
  113.       getNonClientRect(&r);
  114.       invalidateRect(&r);
  115.     }
  116.  
  117.       virtualX=x; virtualY=y;
  118.       if (w != AUTOWH) virtualW=w;
  119.       if (h != AUTOWH) virtualH=h;
  120.  
  121.     if (isVisible()) {
  122.       RECT r;
  123.       getNonClientRect(&r);
  124.       invalidateRect(&r);
  125.     }
  126.  
  127.     setRSize(x, y, w, h);
  128.  
  129.       onResize();
  130.   } else
  131.    VIRTUALWND_PARENT::resize(x, y, w, h);
  132. }
  133.  
  134. //CUTvoid VirtualWnd::resize(RECT *r) {
  135. //CUT  resize(r->left, r->top, r->right-r->left, r->bottom-r->top);
  136. //CUT}
  137.  
  138. void VirtualWnd::move(int x, int y) {
  139.   if (!bypassvirtual) {
  140.     if (isVisible()) {
  141.       RECT r;
  142.       getNonClientRect(&r);
  143.       invalidateRect(&r);
  144.     }
  145.  
  146.       virtualX=x; virtualY=y;
  147.  
  148.     if (isVisible()) {
  149.       RECT r;
  150.       getNonClientRect(&r);
  151.       invalidateRect(&r);
  152.     }
  153.   } else
  154.    VIRTUALWND_PARENT::move(x, y);
  155. }
  156.  
  157. void VirtualWnd::invalidate() {
  158.   if (!bypassvirtual) {
  159.     if (!getRootParent()) return;
  160.     RECT r(clientRect());
  161.     getRootParent()->invalidateRectFrom(&r, this);
  162. //    VIRTUALWND_PARENT::invalidate();    
  163.   } else
  164.    VIRTUALWND_PARENT::invalidate();
  165. }
  166.  
  167. void VirtualWnd::invalidateRect(RECT *r) {
  168.   if (!bypassvirtual) {
  169.       if(!getRootParent()) return;
  170.       getRootParent()->invalidateRectFrom(r, this);
  171.   } else
  172.    VIRTUALWND_PARENT::invalidateRect(r);
  173. }
  174.  
  175. void VirtualWnd::invalidateRgn(Region *reg) {
  176.   if (!bypassvirtual) {
  177.     if(!getRootParent()) return;
  178.     getRootParent()->invalidateRgnFrom(reg, this);
  179.   } else
  180.    VIRTUALWND_PARENT::invalidateRgn(reg);
  181. }
  182.  
  183. void VirtualWnd::validate() {
  184.   if (!bypassvirtual) {
  185.       if(!getRootParent()) return;
  186.       RECT r;
  187.       getClientRect(&r);
  188.       getRootParent()->validateRect(&r);
  189.   } else
  190.    VIRTUALWND_PARENT::validate();
  191. }
  192.  
  193. void VirtualWnd::validateRect(RECT *r) {
  194.   if (!bypassvirtual) {
  195.       if(!getRootParent()) return;
  196.       getRootParent()->validateRect(r);
  197.   } else
  198.    VIRTUALWND_PARENT::validateRect(r);
  199. }
  200.  
  201. void VirtualWnd::validateRgn(Region *reg) {
  202.   if (!bypassvirtual) {
  203.     if(!getRootParent()) return;
  204.     getRootParent()->validateRgn(reg);
  205.   } else
  206.    VIRTUALWND_PARENT::validateRgn(reg);
  207. }
  208.  
  209. void VirtualWnd::getClientRect(RECT *rect) {
  210.   if (!bypassvirtual) {
  211.       // CT:getClientRect behaves differently here for virtual windows
  212.       //    so we can use onPaint directly on the destination canvas
  213.       //    without using another temporary canvas.
  214.       rect->left=virtualX; rect->right=virtualX+virtualW;
  215.       rect->top=virtualY; rect->bottom=virtualY+virtualH;
  216.   //        rect->left=0; rect->right=virtualW;
  217.   //        rect->top=0; rect->bottom=virtualH;
  218.   } else
  219.    VIRTUALWND_PARENT::getClientRect(rect);
  220. }
  221.  
  222. /*void VirtualWnd::getNonClientRect(RECT *rect) {
  223.   getClientRect(rect);
  224. }*/
  225.  
  226. void VirtualWnd::getWindowRect(RECT *rect) {
  227.   if (!bypassvirtual) {
  228.       RECT a;
  229.       getParent()->getWindowRect(&a);
  230.       rect->left=a.left+virtualX; rect->right=rect->left+virtualW;
  231.       rect->top=a.top+virtualY; rect->bottom=rect->top+virtualH;
  232.   } else
  233.    VIRTUALWND_PARENT::getWindowRect(rect);
  234. }
  235.  
  236. int VirtualWnd::beginCapture() {
  237.   if (!bypassvirtual) {
  238.       getRootParent()->setVirtualChildCapture(this);
  239.       return 1;
  240.   } else
  241.    return VIRTUALWND_PARENT::beginCapture();
  242. }
  243.  
  244. int VirtualWnd::endCapture() {
  245.   if (!bypassvirtual) {
  246.     ASSERT(getRootParent() != NULL);
  247.       getRootParent()->setVirtualChildCapture(NULL);
  248.       return 1;
  249.   } else
  250.    return VIRTUALWND_PARENT::endCapture();
  251. }
  252.  
  253. int VirtualWnd::getCapture() {
  254.   if (!bypassvirtual) {
  255.     ASSERT(getRootParent() != NULL);
  256.     return getRootParent()->getVirtualChildCapture() == this;
  257.   } else
  258.    return VIRTUALWND_PARENT::getCapture();
  259. }
  260.  
  261. /*void VirtualWnd::setVirtualChildCapture(BaseWnd *child) {
  262.   if (!bypassvirtual) {
  263.       getParent()->setVirtualChildCapture(child);
  264.   } else
  265.    VIRTUALWND_PARENT::setVirtualChildCapture(child);
  266. }
  267.  
  268. int VirtualWnd::setVirtualChildTimer(BaseWnd *child, int id, int ms) {
  269.   if (!bypassvirtual) {
  270.       return(getParent()->setVirtualChildTimer(child, id, ms));
  271.   } else
  272.    return VIRTUALWND_PARENT::setVirtualChildTimer(child, id, ms);
  273. }
  274.  
  275. int VirtualWnd::killVirtualChildTimer(BaseWnd *child, int id) {
  276.   if (!bypassvirtual) {
  277.       return(getParent()->killVirtualChildTimer(child, id));
  278.   } else
  279.    return VIRTUALWND_PARENT::killVirtualChildTimer(child, id);
  280. }*/
  281.  
  282. void VirtualWnd::setVisible(int show) {
  283.   if (!bypassvirtual) {
  284.     if (visible == !!show) return;
  285.     visible = !!show;
  286.     invalidate();
  287.     onSetVisible(show);
  288.   } else
  289.    VIRTUALWND_PARENT::setVisible(show);
  290. }
  291.  
  292. int VirtualWnd::isVisible() {
  293.   if (!bypassvirtual) {
  294.     return (visible && getParent()->isVisible());
  295.   } else
  296.    return VIRTUALWND_PARENT::isVisible();
  297. }
  298.  
  299. // eek
  300. void VirtualWnd::repaint() {
  301.   if (!bypassvirtual) {
  302.     if(!getParent()) return;
  303.     getParent()->repaint(); 
  304.   } else
  305.    VIRTUALWND_PARENT::repaint();
  306. }
  307.  
  308. int VirtualWnd::isInited() {
  309.   if (!bypassvirtual) {
  310.     return inited;
  311.   } else
  312.    return VIRTUALWND_PARENT::isInited();
  313. }
  314.  
  315. // those two will need to touch WindowTracker::allWnd order as well as parent's virtualChildren list
  316. void VirtualWnd::moveToFront() {
  317.   //ASSERTPR(0, "Implement me!");
  318. }
  319.  
  320. void VirtualWnd::moveToBack() {
  321.   //ASSERTPR(0, "Implement me!");
  322. }
  323.  
  324. /*int VirtualWnd::focusNextSibbling(int dochild) {
  325.   return 1;
  326. }
  327.  
  328. int VirtualWnd::focusNextVirtualChild(BaseWnd *child) {
  329.   return 1;
  330. }*/
  331.  
  332. int VirtualWnd::cascadeRepaint() {
  333.   if (!bypassvirtual) {
  334.     if (getRootParent()) {
  335.       RECT r;
  336.       VirtualWnd::getNonClientRect(&r);
  337.       getRootParent()->cascadeRepaintRectFrom(&r, this);
  338.     }
  339.     return 1;
  340.   } else
  341.    return VIRTUALWND_PARENT::cascadeRepaint();
  342. }
  343.  
  344. int VirtualWnd::cascadeRepaintRect(RECT *r) {
  345.   if (!bypassvirtual) {
  346.     if (getRootParent()) {
  347.       getRootParent()->cascadeRepaintRectFrom(r, this);
  348.     }
  349.     return 1;
  350.   } else
  351.    return VIRTUALWND_PARENT::cascadeRepaintRect(r);
  352. }
  353.  
  354. int VirtualWnd::cascadeRepaintRgn(Region *r) {
  355.   if (!bypassvirtual) {
  356.     if (getRootParent()) {
  357.       getRootParent()->cascadeRepaintRgnFrom(r, this);
  358.     }
  359.     return 1;
  360.   } else
  361.    return VIRTUALWND_PARENT::cascadeRepaintRgn(r);
  362. }
  363.  
  364. /*RootWnd *VirtualWnd::getWindowBehindMyself(int x, int y) {
  365.   RECT r;
  366.   if (!bypassvirtual) {
  367.     if (!getParent()) return NULL;
  368.     int n = getParent()->getNumVirtuals();
  369.  
  370.     RootWnd *c = NULL;
  371.  
  372.     for (int i=n-1;i>=0;i++) {
  373.       c = getParent()->getVirtualChild(i);
  374.       if (c == this) break;
  375.     }
  376.  
  377.     i--;
  378.     if (i < 0) return getParent();
  379.  
  380.     for (;i>=0; i--) {
  381.       c = getParent()->getVirtualChild(i);
  382.       c->getNonClientRect(&r);
  383.       if (x>=r.left&&x<=r.right&&y>=r.top&&y<=r.bottom)
  384.         return c;
  385.     }
  386.     return getParent();
  387.   } else
  388.    return NULL;
  389. }*/
  390.  
  391. RootWnd *VirtualWnd::rootWndFromPoint(POINT *pt) {
  392.   if (!bypassvirtual) {
  393.     if (!getParent()) return NULL;
  394.     return getParent()->rootWndFromPoint(pt);
  395.   } else
  396.    return VIRTUALWND_PARENT::rootWndFromPoint(pt);
  397. }
  398.  
  399. double VirtualWnd::getRenderRatio() {
  400.   if (!bypassvirtual) {
  401.     if (!getParent()) return 1.0;
  402.     return getParent()->getRenderRatio();
  403.   } else
  404.    return VIRTUALWND_PARENT::getRenderRatio();
  405. }
  406.  
  407. void VirtualWnd::bringToFront() {
  408.   if (!bypassvirtual) {
  409.     if(!getParent()) return;
  410.     getParent()->bringVirtualToFront(this);
  411.   }/* else
  412.    VIRTUALWND_PARENT::bringToFront();*/
  413. }
  414.  
  415. void VirtualWnd::bringToBack() {
  416.   if (!bypassvirtual) {
  417.     if(!getParent()) return;
  418.     getParent()->bringVirtualToBack(this);
  419.   } /*else
  420.    VIRTUALWND_PARENT::bringToBack();*/
  421. }
  422.  
  423. void VirtualWnd::bringAbove(BaseWnd *o) {
  424.   if (!bypassvirtual) {
  425.     if(!getParent()) return;
  426.     getParent()->bringVirtualAbove(this, o);
  427.   }/* else
  428.    VIRTUALWND_PARENT::bringAbove();*/
  429. }
  430.  
  431. void VirtualWnd::bringBelow(BaseWnd *o) {
  432.   if (!bypassvirtual) {
  433.     if(!getParent()) return;
  434.     getParent()->bringVirtualBelow(this, o);
  435.   }/* else
  436.    VIRTUALWND_PARENT::bringBelow();*/
  437. }
  438.  
  439. void VirtualWnd::postDeferredCallback(int param1, int param2) {
  440.   ASSERT(getRootParent() && getRootParent()->gethWnd());
  441.   if (!bypassvirtual) {
  442.     defered_callback *c = new defered_callback;
  443.     c->origin = this;
  444.     c->param1 = param1;
  445.     c->param2 = param2;
  446.     PostMessage(getRootParent()->gethWnd(), UMSG_DEFERRED_CALLBACK, (WPARAM)NULL, (LPARAM)c);
  447.   } else
  448.    VIRTUALWND_PARENT::postDeferredCallback(param1, param2);
  449. }
  450.  
  451. int VirtualWnd::reparent(RootWnd *newparent) {
  452.   if (!bypassvirtual) {
  453.     if (getParent()) 
  454.       getParent()->removeVirtualChild(this);
  455.     parentWnd = NULL;
  456.     newparent->addVirtualChild(this);
  457.     onSetParent(newparent);
  458.     newparent->invalidate();
  459.     return 1;
  460.   } else {
  461.    return VIRTUALWND_PARENT::reparent(newparent);
  462.   }
  463. }
  464.  
  465. int VirtualWnd::setVirtual(int i) {
  466.  
  467.   ASSERT(!isInited()); // cut
  468.  
  469.   if (isInited()) return 0; 
  470.   bypassvirtual = !i;
  471.   return 1;
  472. }
  473.  
  474. RootWnd *VirtualWnd::getRootParent() {
  475.   if (!bypassvirtual) {
  476.     if (!getParent()) return NULL;
  477.     RootWnd *t = this;
  478.     while (t->isVirtual()) {
  479.       if (!t->getParent()) return NULL;
  480.       t = t->getParent();
  481.     }
  482.     return t;
  483.   } else {
  484.     return VIRTUALWND_PARENT::getRootParent();
  485.   }
  486. }
  487.  
  488.  
  489. /* todo:  setCursor 
  490.           setFocus
  491.           
  492.    + real childs going invisible should deferedInvalidate their rect on their parent window if it has a virtualCanvas
  493. */          
  494.           
  495.  
  496.  
  497. // No need for screenToClient/clientToScreen overrides since the virtual's origin is the same as it's parent
  498.